package com.tiantai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiantai.common.annotation.Log;
import com.tiantai.common.core.controller.BaseController;
import com.tiantai.common.core.domain.AjaxResult;
import com.tiantai.common.enums.BusinessType;
import com.tiantai.system.domain.TeaManagement;
import com.tiantai.system.service.ITeaManagementService;
import com.tiantai.common.utils.poi.ExcelUtil;
import com.tiantai.common.core.page.TableDataInfo;

/**
 * 茶叶份额Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/management")
public class TeaManagementController extends BaseController
{
    @Autowired
    private ITeaManagementService teaManagementService;

    /**
     * 查询茶叶份额列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaManagement teaManagement)
    {
        startPage();
        List<TeaManagement> list = teaManagementService.selectTeaManagementList(teaManagement);
        return getDataTable(list);
    }

    /**
     * 导出茶叶份额列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "茶叶份额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaManagement teaManagement)
    {
        List<TeaManagement> list = teaManagementService.selectTeaManagementList(teaManagement);
        ExcelUtil<TeaManagement> util = new ExcelUtil<TeaManagement>(TeaManagement.class);
        util.exportExcel(response, list, "茶叶份额数据");
    }

    /**
     * 获取茶叶份额详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaManagementService.selectTeaManagementById(id));
    }

    /**
     * 新增茶叶份额
     */
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "茶叶份额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaManagement teaManagement)
    {
        return toAjax(teaManagementService.insertTeaManagement(teaManagement));
    }

    /**
     * 修改茶叶份额
     */
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "茶叶份额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaManagement teaManagement)
    {
        return toAjax(teaManagementService.updateTeaManagement(teaManagement));
    }

    /**
     * 删除茶叶份额
     */
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "茶叶份额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaManagementService.deleteTeaManagementByIds(ids));
    }
}
